<?xml version='1.0' encoding='UTF-8' ?>
<!--

    Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.

    This program and the accompanying materials are made available under the
    terms of the Eclipse Public License v. 2.0, which is available at
    http://www.eclipse.org/legal/epl-2.0.

    This Source Code may also be made available under the following Secondary
    Licenses when the conditions for such availability set forth in the
    Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
    version 2 with the GNU Classpath Exception, which is available at
    https://www.gnu.org/software/classpath/license.html.

    SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0

-->

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:cc="http://java.sun.com/jsf/composite"
                xmlns:h="http://java.sun.com/jsf/html">

    <cc:interface>
        <cc:attribute name="label" required="true"/>
        <cc:attribute name="value" required="true"/>
        <cc:editableValueHolder name="value" targets="inputText"/>
        <cc:attribute name="required" type="boolean"/>
        <cc:attribute name="requiredMessage"/>
        <cc:attribute name="editable" required="true" type="boolean"/>
        <cc:attribute name="helpText" required="false"/>
        <cc:attribute name="validator" required="false" targets="inputText"
                      method-signature="void validate(javax.faces.context.FacesContext,javax.faces.component.UIComponent,java.lang.Object)"/>
        <cc:attribute name="validatorMessage"/>
    </cc:interface>

    <cc:implementation>
        <div>
            <h:outputLabel for="inputText" value="#{cc.attrs.label}"/>
            <h:inputText id="inputText" 
                         disabled="#{!cc.attrs.editable}"
                         required="#{cc.attrs.required}" 
                         requiredMessage="#{cc.attrs.requiredMessage}"
                         value="#{cc.attrs.value}"
                         validatorMessage="#{cc.attrs.validatorMessage}">
            </h:inputText>

            <h:panelGroup layout="block" 
                          rendered="#{!(empty cc.attrs.helpText) and cc.attrs.editable}">
                <i>#{cc.attrs.helpText}</i>
            </h:panelGroup>
        </div>
        <div>
            <h:messages/>
        </div>
    </cc:implementation>
</ui:composition>
